//
//  MKHomeSectionHeader.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/11.
//  Copyright © 2017年 cc.moko. All rights reserved.
//  section Header

import UIKit

class MKHomeSectionHeader: UIView {

    var title:UILabel!
    var subTitle:UILabel!
    var more:UIButton!
    var line:UIView!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.white
        
        self.title = UILabel.label(fontSize: 15, textColor: UIColorFromRGB(rgbValue: 0x333333, A: 1))
//        self.title.backgroundColor = UIColor.randomColor()
        self.addSubview(self.title)
        
        self.subTitle = UILabel.init()
//        self.subTitle.backgroundColor = UIColor.randomColor()
        self.subTitle.font = UIFont.init(name: "STHeitiSC-Light", size: 12)
        self.subTitle.textColor = UIColorFromRGB(rgbValue: 0x999999, A: 1)
        self.addSubview(self.subTitle)
        
        self.line = UIView.init()
        self.line.backgroundColor = UIColorFromRGB(rgbValue: 0xe5e5e5, A: 1)
        self.addSubview(self.line)
        
        self.more = UIButton.init()
        self.more.setImage(UIImage.init(named: "moremore"), for: .normal)
        self.addSubview(self.more)
    }
    func config(title:String,subTitle:String,moreHiden:Bool) -> Void {
        
        self.title.text = title
        self.subTitle.text = subTitle
        self.more.isHidden = moreHiden
        self.setNeedsLayout()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.title.sizeToFit()
        self.subTitle.sizeToFit()
        self.title.frame = CGRect.init(x: (self.width - self.title.width) * 0.5, y: 11, width: self.title.width, height: self.title.height)
        self.subTitle.frame = CGRect.init(x: (self.width - self.subTitle.width) * 0.5, y: (self.height - self.subTitle.height - 8), width: self.subTitle.width, height: self.subTitle.height)
        
        self.more.frame = CGRect.init(x: self.width - 10 - 60, y: (self.height - 40) * 0.5, width: 60, height: 40)
        self.line.frame = CGRect.init(x: 0, y: self.height - 0.5, width: self.width, height: 0.5)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
